import axios from 'axios'
import {Message} from 'element-ui'
import router from '@/router/index'
import {removeToken} from '@/utils/cookie'

const MyHttpService = {}

MyHttpService.install = (Vue) => {
  axios.defaults.baseURL = "http://zs.91gongju.cn:10003"
  // axios.defaults.baseURL = "http://localhost:10003"
  /** 添加相应拦截器*/
  axios.interceptors.response.use(function (response) {
    console.log('响应数据 拦截器', response)
    if (response.data.code === 401) {
      removeToken()
      router.push({path: '/'})
      router.push({path: '/view'})
      window.location.path('/view')
    } else if (response.data.msg === '抖音授权过期！') {
      Message.warning('抖音授权过期,重新授权')
    } else {
      return response;
    }
    return response;
  }, function (error) {

    return Promise.reject(error)
  })
  Vue.prototype.$http = axios

}
export default MyHttpService
